/*
 * @Author: 别拿暗恋当饭吃. 13466071+lililkli@user.noreply.gitee.com
 * @Date: 2024-06-24 16:47:04
 * @LastEditors: 别拿暗恋当饭吃. 13466071+lililkli@user.noreply.gitee.com
 * @LastEditTime: 2024-06-24 17:20:26
 * @FilePath: \rabce\project\src\services\user.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
// import { RegisterData } from "./user";
// import { doRegister } from "./../store/user/index";
import Axios from "utils/Axios";
// import { getEncryptPwd } from "utils/helper";
import { getEntry } from "utils/helper";
// import { RegisterData } from "./user";
// import { doRegister } from "./../store/user/index";
// import { getEntry } from "utils/helper";
export const doGetUserList = () => {
  return new Promise((resolve, reject) => {
    setTimeout(() => {
      resolve([
        {
          name: "张三",
          age: 18,
          email: "123456@aa.com",
        },
      ]);
      //   reject("你错啦");
    }, 500);
  });
};

export const doSendEmailCode = (email: string) => {
  return Axios.postFromData("/api/sendOutEmailCode", {
    data: { email },
  }).then((res) => res);
};

// export type RegisterData = {
//   email: string;
//   code: string | number;
//   pwd1: string;
//   pwd2: string;
// };
// export const doRegister = (data: RegisterData) => {
//   //register
//   data.pwd1 = getEntry(data.pwd1) as string;
//   data.pwd2 = data.pwd1;

//   return Axios.postFromData("/api/register", { data }).then((res) => {
//     console.log(res);
//   });
// };

export type RegisterData = {
  email: string;
  code: string;
  pwd1: string;
  pwd2: string;
};

export const doRegister = (data: RegisterData) => {
  console.log("我是api:", data);

  const pwd1 = getEncryptPwd(data.pwd1);

  data.pwd1 = pwd1 as string;
  data.pwd2 = data.pwd1;

  Axios.postFromData("/api/user/register", { data }).then((res) => {
    console.log(res);
    return res;
  });

  //   return Promise.resolve();
};
